package cn.com.coding.common.utils;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class ReadOrder {
    public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {

        testCopyToLocalFile();
    }

    public static void testCopyToLocalFile() throws IOException, InterruptedException, URISyntaxException {
        System.setProperty("HADOOP_USER_NAME", "codingce");
        Configuration conf = new Configuration();
        conf.set("dfs.replication", "2");
        conf.set("dfs.client.socket-timeout", "300000");
        //添加此配置信息即可
        conf.set("dfs.client.use.datanode.hostname", "true");

        // 1 获取文件系统
        FileSystem fs = FileSystem.get(new URI("hdfs://8.130.17.56:8020"), conf, "codingce");
        // 2 执行下载操作
        // boolean delSrc 指是否将原文件删除
        // Path src 指要下载的文件路径
        // Path dst 指将文件下载到的路径
        // boolean useRawLocalFileSystem 是否开启文件校验 fs.copyToLocalFile(false, new
        fs.copyToLocalFile(false, new Path("/opt/module/user_card_product/user_card_product/part-r-00000"), new Path("/Users/inke219223m/mxz-code/gitee/cat-leader/cat-common/src/main/java/cn/com/coding/common/utils/order.txt"), true);
        // 3 关闭资源
        fs.close();
    }
}
